using System;
using System.Collections.Generic;
using System.Text;
using System.IO.IsolatedStorage;
using System.IO;
using System.ComponentModel;

namespace GoScreenSaver
{
    public static class IsolatedStoreDataSource
    {
        static IsolatedStorageFile isoStore = IsolatedStorageFile.GetMachineStoreForAssembly();
        const String FileName = "GoScreenSaver.txt";
        const String glGoFileName = "C:\\Program Files\\glGo\\glGo.exe";
        const String GLGOFILENAME_KEY = "glGoFileName";

        public static String GlGoFileName
        {
            get
            {
                String val = Read(GLGOFILENAME_KEY);
                return val ?? glGoFileName;
            }

            set
            {
                Write(value);
            }
        }


        public static String Read(String key)
        {
            StreamReader reader = new StreamReader(new IsolatedStorageFileStream(FileName, FileMode.OpenOrCreate, FileAccess.Read, isoStore));
            String s;
            while ((s = reader.ReadLine()) != null && !s.StartsWith(key + "=")) ;
            reader.Close();
            if (String.IsNullOrEmpty(s)) return null;
            return s.Substring((key + "=").Length);
        }

        public static void Write(String _glGoFileName)
        {
            StreamWriter writer = null;
            writer = new StreamWriter(new IsolatedStorageFileStream(FileName, FileMode.Create, isoStore));
            writer.WriteLine(GLGOFILENAME_KEY + "=" + _glGoFileName);
            writer.Close();
        }

    }
}
